<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true">
      <el-form-item label="班组长姓名" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入姓名"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:role:add']"
        >新增</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table  v-loading="loading" :data="equipmentList">
      <el-table-column prop="equipmentId" label="手环编号"></el-table-column>
      <el-table-column prop="userName" label="班组长姓名"></el-table-column>
      <el-table-column prop="userId" label="班组长id"></el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row.id)"
            v-hasPermi="['system:user:edit']"
            >修改</el-button>
          <el-button
            v-if="scope.row.userId !== 1"
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row.id)"
            v-hasPermi="['system:user:remove']"
            >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.page"
      :limit.sync="queryParams.limit"
      @pagination="getList"
    />

    <!-- 修改角色配置对话框 -->

    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="手环编号" prop="equipmentId">
          <el-input v-model="form.equipmentId" disabled />
        </el-form-item>
        <el-form-item label="班组长名称" prop="userName">
          <el-input v-model="form.userName" placeholder="请输入角色名称" />
        </el-form-item>
        <el-form-item label="班组长id" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入角色名称" />
        </el-form-item>
        <el-form-item label="id" prop="id" class="disdiv">
          <el-input v-model="form.id" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 新增弹窗 -->
    <el-dialog :title="title" :visible.sync="dialogVisible" width="500px" append-to-body>
      <el-form ref="addform" :model="addform" :rules="rulesadd" label-width="100px">
        <el-form-item label="手环姓名" prop="equipmentId">
          <el-select v-model="addform.equipmentId" placeholder="请选择人员姓名" class="ovdiv">
            <el-option v-for="item in addoption" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="班组长名称" prop="userName">
          <el-input v-model="addform.userName" placeholder="请输入角色名称" />
        </el-form-item>
        <el-form-item label="班组长id" prop="userId">
          <el-input v-model="addform.userId" placeholder="请输入角色名称" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormadd">确 定</el-button>
        <el-button @click="canceladd">取 消</el-button>
      </div>
    </el-dialog>
    <!-- <div id="heihei"></div> -->
  </div>
</template>

<script>
import { selectBanZhuList, selectBanZhuDetail, getSBList, addBanZhuInfo, deleteBanZU,updateBanZhuInfo } from "@/api/bracelet/equipment";
export default {
  data() {
    return {
      // 遮罩层
      loading: true,
      equipmentList: [],
      total: 0,
      // 显示搜索条件
      showSearch: true,
      open: false,
      loadinginfo: true,
      title:'',
      // 查询参数
      queryParams: {
        limit: 10,
        page: 1
      },
      shebeiinfo: {
        blood_time: "",
        heart_rate: "",
        heart_time: "",
        max_rate: "",
        min_rate: "",
        temperature: "",
        temperature_time: "",
      },
      //新增按钮弹出框
      dialogVisible: false,
      addoption:[],
      labeloptions: [{
          value: '689466010026384',
          label: '谭国和'
        }, {
          value: '689466010016153',
          label: '孙雅琳'
        }, {
          value: '689466010025931',
          label: '王学富'
        }, {
          value: '689466020019593',
          label: '杨玉杰'
        }, {
          value: '689466010025444',
          label: '斯钦巴图'
        }],
      opvalue:'',
      addVlaue:'',
      inputvla:'',
      // 表单参数
      form: {},
      addform:{},
      // 表单校验
      rules: {
        userName: [
          { required: true, message: "班组长名称不能为空", trigger: "blur"}
        ],
        userId: [
          { required: true, message: "班组长id不能为空", trigger: "blur"}
        ]
      },
      rulesadd: {
        equipmentId: [
          { required: true, message: "设备名称不能为空", trigger: "blur"}
        ],
        userName: [
          { required: true, message: "班组长名称不能为空", trigger: "blur"}
        ],
        userId: [
          { required: true, message: "班组长id不能为空", trigger: "blur"}
        ]
      }
    }
  },
  created() {
    this.getList()
  },
  mounted() {
    // this.echt()
  },
  methods: {
    echt() {
      // 基于准备好的dom，初始化echarts实例
      var myChart = this.$echarts.init(document.getElementById('heihei'));
      // 绘制图表
      myChart.setOption({
        title: {
          text: 'ECharts 入门示例'
        },
        tooltip: {},
        xAxis: {
          data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
        },
        yAxis: {},
        series: [
          {
            name: '销量',
            type: 'bar',
            data: [5, 20, 36, 10, 10, 20]
          }
        ]
      });
    },
    getList() {
      selectBanZhuList(this.queryParams).then(response => {
        this.equipmentList = response.rows
        this.total = response.total
          this.loading = false
      }).catch(function(error) {
        console.log(error);
      });
    },
    caseLineFormat(row) {
      //在线状态
      var showProp = null
      if(row.is_online == "1"){
        showProp = '在线'
      }else {
        showProp = '离线'
      }
      return showProp
    },
    /** 重置按钮操作 */
    resetQuery() {
      // this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },
    handleUpdate(id) {
      //打开详情
      this.open = true;
      this.title = '详情'
      selectBanZhuDetail(id).then(response => {
        this.loadinginfo = false;
        console.log("66666",response);
        this.form = response.data
        this.shebeiinfo = response.data;
      }).catch(function(error) {
        console.log(error);
      });
    },
    closeinfo() {
      //详情弹框关闭
      this.loadinginfo = true
    },
    handleAdd() {
      //新增按钮操作
      getSBList().then(response => {
        this.addoption = response.data;
        var data = response.data;
        if(data.length>0){
          this.dialogVisible = true
        }else{
          this.$message.error('目前没有可以添加的设备信息！');
        }
      }).catch(function(error) {
        console.log(error);
      });
    },
    /** 删除按钮操作 */
    handleDelete(id) {
      this.$confirm('是否确认删除编号为"' + id + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return deleteBanZU(id);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    submitForm:function(){
      this.$refs["form"].validate(valid => {
        if (valid) {
          updateBanZhuInfo(this.form).then(response => {
            this.msgSuccess("编辑成功成功");
            this.open = false;
            this.getList();
          });
        }
      });
    },
    cancel() {
      this.open = false;
      //表单重置方法
      // this.reset()
    },
    submitFormadd:function(){
      this.$refs["addform"].validate(valid => {
        if (valid) {
          addBanZhuInfo(this.addform).then(response => {
            this.msgSuccess("新增成功");
            this.dialogVisible = false;
            this.getList();
            this.canceladd()
          });
        }
      });
    },
    canceladd() {
      this.dialogVisible = false;
      //表单重置方法
      this.resetadd()
    },
    resetadd() {
      this.addform ={}
    }
  }
}
</script>

<style scoped>
#heihei{
  width: 400px;
  height: 400px;
}
.shebeiinfo{
  text-align: center;
}
.center_div{
  width: 100%;
  text-align: center;
}
.ovdiv{
  width: 100%;
}
.disdiv{
  display: none;
}
</style>